package com.ruoyi.service.impl;

import com.ruoyi.domain.ZhwyChargeitem;
import com.ruoyi.domain.ZhwyPaymentmethod;
import com.ruoyi.domain.ZhwyTemporarydeposit;
import com.ruoyi.mapper.ZhwyChargeitemMapper;
import com.ruoyi.mapper.ZhwyHirerMapper;
import com.ruoyi.mapper.ZhwyPaymentmethodMapper;
import com.ruoyi.mapper.ZhwyTemporarydepositMapper;
import com.ruoyi.service.IZhwyTemporarydepositService;
import com.ruoyi.system.domain.ZhwyShops;
import com.ruoyi.system.mapper.ZhwyShopsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 临时收费/押金管理Service业务层处理
 *
 * @author ningning
 * @date 2024-05-07
 */
@Service
public class ZhwyTemporarydepositServiceImpl implements IZhwyTemporarydepositService {
    @Autowired
    private ZhwyTemporarydepositMapper zhwyTemporarydepositMapper;
    @Autowired
    private ZhwyShopsMapper zhwyShopsMapper;
    @Autowired
    private ZhwyChargeitemMapper zhwyChargeitemMapper;
    @Autowired
    private ZhwyPaymentmethodMapper zhwyPaymentmethodMapper;

    /**
     * 查询临时收费/押金管理
     *
     * @param id 临时收费/押金管理主键
     * @return 临时收费/押金管理
     */
    @Override
    public ZhwyTemporarydeposit selectZhwyTemporarydepositById(Long id) {
        return zhwyTemporarydepositMapper.selectZhwyTemporarydepositById(id);
    }

    /**
     * 查询临时收费/押金管理列表
     *
     * @param zhwyTemporarydeposit 临时收费/押金管理
     * @return 临时收费/押金管理
     */
    @Override
    public List<ZhwyTemporarydeposit> selectZhwyTemporarydepositList(ZhwyTemporarydeposit zhwyTemporarydeposit) {
        if (zhwyTemporarydeposit.getShopsCode()!=null){
            ZhwyShops zhwyShops1=new ZhwyShops();
            zhwyShops1.setCode(zhwyTemporarydeposit.getShopsCode());
            List<ZhwyShops> zhwyShopsList = zhwyShopsMapper.selectZhwyShopsList(zhwyShops1);
            ZhwyShops zhwyShops2 = zhwyShopsList.get(0);

            zhwyTemporarydeposit.setShopsId(zhwyShops2.getId());
        }
        List<ZhwyTemporarydeposit> list = zhwyTemporarydepositMapper.selectZhwyTemporarydepositList(zhwyTemporarydeposit);
        for (ZhwyTemporarydeposit ztd : list) {
            ZhwyShops zhwyShops = zhwyShopsMapper.selectZhwyShopsById(ztd.getShopsId());
            ZhwyChargeitem zhwyChargeitem = zhwyChargeitemMapper.selectZhwyChargeitemById(ztd.getChargeItemId());
            ZhwyPaymentmethod zhwyPaymentmethod = zhwyPaymentmethodMapper.selectZhwyPaymentmethodById(ztd.getPayId());
            if(zhwyShops != null){
                ztd.setShopsCode(zhwyShops.getCode());
            }
            if (zhwyChargeitem != null){
                ztd.setChargeItemName(zhwyChargeitem.getName());
            }
            if (zhwyPaymentmethod != null){
                ztd.setPaymentMethodName(zhwyPaymentmethod.getName());
            }
        }
        return list;
    }

    /**
     * 新增临时收费/押金管理
     *
     * @param zhwyTemporarydeposit 临时收费/押金管理
     * @return 结果
     */
    @Override
    public int insertZhwyTemporarydeposit(ZhwyTemporarydeposit zhwyTemporarydeposit) {
        return zhwyTemporarydepositMapper.insertZhwyTemporarydeposit(zhwyTemporarydeposit);
    }

    /**
     * 修改临时收费/押金管理
     *
     * @param zhwyTemporarydeposit 临时收费/押金管理
     * @return 结果
     */
    @Override
    public int updateZhwyTemporarydeposit(ZhwyTemporarydeposit zhwyTemporarydeposit) {
        zhwyTemporarydeposit.setState(0L);
        int row = zhwyTemporarydepositMapper.updateZhwyTemporarydeposit(zhwyTemporarydeposit);
        return row;
    }

    /**
     * 批量删除临时收费/押金管理
     *
     * @param ids 需要删除的临时收费/押金管理主键
     * @return 结果
     */
    @Override
    public int deleteZhwyTemporarydepositByIds(Long[] ids) {
        return zhwyTemporarydepositMapper.deleteZhwyTemporarydepositByIds(ids);
    }

    /**
     * 删除临时收费/押金管理信息
     *
     * @param id 临时收费/押金管理主键
     * @return 结果
     */
    @Override
    public int deleteZhwyTemporarydepositById(Long id) {
        return zhwyTemporarydepositMapper.deleteZhwyTemporarydepositById(id);
    }
}
